SQL: A Step By Step Guide To Learn SQL For Absolute Beginner by Trinity Lilly

SQL: A Step By Step Guide To Learn SQL For Absolute Beginner by Trinity Lilly

Author:Trinity, Lilly [Trinity, Lilly]
Language: eng
Format: epub
Published: 2019-12-31T16:00:00+00:00


Set Operators

The SQL language includes three set operators that allow you to perform each of the various set operations described earlier in the chapter. Additionally, each set operator has two flavors, one that includes duplicates and another that removes duplicates (but not necessarily all of the duplicates). The following subsections define each operator and demonstrate how they are used.

The Union Operator

The union and union all operators allow you to combine multiple data sets. The difference between the two is that union sorts the combined set and removes duplicates, whereas union all does not. With union all, the number of rows in the final data set will always equal the sum of the number of rows in the sets being combined. This operation is the simplest set operation to perform (from the server’s point of view), since there is no need for the server to check for overlapping data. The following example demonstrates how you can use the union all operator to generate a full set of customer data from the two customer subtype tables:

mysql> SELECT 'IND' type_cd, cust_id, lname name

-> FROM individual

-> UNION ALL

-> SELECT 'BUS' type_cd, cust_id, name

-> FROM business;



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.